package com.caption.auth.service.impl;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.caption.auth.mapper.SysUserMapper;
import com.caption.auth.model.entity.SysPermission;
import com.caption.auth.model.entity.SysRole;
import com.caption.auth.model.entity.SysUser;
import com.caption.auth.service.SysUserService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @description: 获取登录用户信息
 * @author: 码农
 * @date: 2022-01-01 11:11:46
 */
@Service
@DS(value = "user_db")
public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> implements SysUserService {

    public SysUser selectByPhone(String phone){
        QueryWrapper<SysUser> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(SysUser::getPhone, phone);
        return this.baseMapper.selectOne(queryWrapper);
    }

    public SysUser selectByUserName(String userName) {
        QueryWrapper<SysUser> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(SysUser::getUserName, userName);
        return this.baseMapper.selectOne(queryWrapper);
    }

    @Override
    public List<SysRole> selectRoleByUserId(Long userId) {
        return this.baseMapper.selectRoleByUserId(userId);
    }

    @Override
    public List<SysPermission> selectPermissionByUserId(Long userId) {
        return baseMapper.selectPermissionByUserId(userId);
    }

}
